namespace CRMG.Container.Source.DL
{
    using CRMG.Container.Source.BO;
    using CRMG.Container.Source.QO;
    using Guru.Framework.BaseDal;
    using Guru.Framework.QueryBuilding;
    using Guru.Framework.Util;
    using System;
    using System.Data;

    public class AvailableTrainDL : BaseDL
    {

        public AvailableTrainDL()
        {
        }

        public DataTable GetAvailableTrains()
        {
            try
            {
                return base.Manager.GetResultSet(Crud.GetAvailableTrains()).Tables[0];
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }

        public AvailableTrain GetAvailableTrainById(int availableTrainId)
        {
            try
            {
                AvailableTrain avTrain = new AvailableTrain() { OBJID = availableTrainId };
                QueryBuilder qB = Manager.CreateQueryBuilder(QueryTypes.SelectWhereId, avTrain);
                DataTable dt = Manager.GetResultSet(qB.QueryString, qB.QueryParameters).Tables[0];
                avTrain = null;
                foreach (DataRow row in dt.Rows)
                {
                    avTrain = new AvailableTrain()
                    {
                        OBJID = ConverterUtil.Convert2Int(row["OBJID"]),
                        TrainId = ConverterUtil.Convert2Int(row["TrainId"]),
                        UserId = ConverterUtil.Convert2Int(row["UserId"]),
                        TrainClassId = ConverterUtil.Convert2Int(row["TrainClassId"]),
                        TrainAmount = ConverterUtil.Convert2Int(row["TrainAmount"]),
                        StartTime = ConverterUtil.ConvertString2DateTime(row["StartTime"].ToString()),
                        EndTime = ConverterUtil.ConvertString2DateTime(row["EndTime"].ToString()),
                    };
                }
                return avTrain;
            }
            catch (Exception)
            {
                throw;
            }
        }

    }
}

